<?php
global $Config;
require_once($Config->WebCMSRoot.'Base/View.php');

Class MapView extends BaseView
{
	function MapView()
	{
		parent::BaseView();
	}
	
	function ShowMap($map, $apiKey, $width=500, $height=300)
	{
//print('<pre>'.var_export($map, true).'</pre>');exit;
//print('<pre>'.var_export($this, true).'</pre>');exit;
		$this->output  = '<h2>'.$map->Name.'</h2>'."\n";
		$this->output .= '<p>'.htmlentities($map->Address).'<br />';
		$this->output .= 'Routebeschrijving: <a href="http://maps.google.be/maps?f=q&hl=nl&geocode=&q='.urlencode($map->Address).'&ll='.$map->Latitude.','.$map->Longitude.'&z=15&iwloc=addr&om=1" target="_blank">Google Maps</a>';
		$this->output .= '</p>'."\n";
		$this->output .= '<script src="http://maps.google.com/maps?file=api&amp;v=2&amp;hl=nl&amp;key='.$apiKey.'" type="text/javascript"></script>'."\n";
		$this->output .= '<script type="text/javascript">'."\n";
		$this->output .= '//<![CDATA['."\n";
		$this->output .= '$(document).ready(function() {'."\n";
		$this->output .= '    if (GBrowserIsCompatible()) {'."\n";
		$this->output .= '        var map = new GMap2(document.getElementById("map"));'."\n";
		$this->output .= '        map.addControl(new GSmallMapControl());'."\n";
		$this->output .= '        map.addControl(new GMapTypeControl());'."\n";
		$this->output .= '        map.setCenter(new GLatLng('.$map->Latitude.', '.$map->Longitude.'), '.$map->ZoomLevel.');'."\n";
		$this->output .= '        var marker = new GMarker(map.getCenter());'."\n";
		//$this->output .= '        GEvent.addListener(marker, "click", function() {'."\n";
		//$this->output .= '            marker.openInfoWindowHtml("<b>'.htmlentities($map->Name).'</b><br />';
		//$this->output .= htmlentities($map->Address).'<br />';
		//$this->output .= '<br />Routebeschrijving: <a href=\"http://maps.google.be/maps?f=q&hl=nl&geocode=&q='.urlencode($map->Address).'&ll='.$map->Latitude.','.$map->Longitude.'&z=15&iwloc=addr&om=1\" target=\"_blank\">Google Maps</a>");'."\n";
		//$this->output .= '        });'."\n";
		$this->output .= '        map.openInfoWindowHtml(map.getCenter(),"<b>'.htmlentities($map->Name).'</b><br />';
		$this->output .= str_replace(',','<br />',htmlentities($map->Address)).'<br />';
		$this->output .= '<br />Routebeschrijving: <a href=\"http://maps.google.be/maps?f=q&hl=nl&geocode=&q='.urlencode($map->Address).'&ll='.$map->Latitude.','.$map->Longitude.'&z=15&iwloc=addr&om=1\" target=\"_blank\">Google Maps</a>");'."\n";
		$this->output .= '        map.addOverlay(marker);'."\n";
		$this->output .= '    }'."\n";
		$this->output .= '})'."\n";
		$this->output .= 'window.onunload = GUnload;'."\n";
		$this->output .= '//]]>'."\n";
		$this->output .= '</script>'."\n";
		$this->output .= '<div id="map" style="width: '.$width.'px; height: '.$height.'px"></div>';
	}
}
?>